package com.wannengbang.cloudleader.performance.model;


import com.wannengbang.cloudleader.appconst.MethodType;
import com.wannengbang.cloudleader.appconst.URLConst;
import com.wannengbang.cloudleader.base.DataCallBack;
import com.wannengbang.cloudleader.bean.StatisticsBean;
import com.wannengbang.cloudleader.bean.StatisticsTypeBean;
import com.wannengbang.cloudleader.retorfit_manager.ResponseObserver;
import com.wannengbang.cloudleader.retorfit_manager.RetrofitHelper;
import com.wannengbang.cloudleader.utils.ToastUtil;

import java.util.HashMap;
import java.util.Map;

public class PerformanceModelImpl implements IPerformanceModel {

    @Override
    public void requestStatistics(DataCallBack<StatisticsBean> callBack) {
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.STATISTICS, null, new ResponseObserver<StatisticsBean>() {
            @Override
            public void onSuccessful(StatisticsBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(StatisticsBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestLineStatistics(String cycleType, String param, DataCallBack<StatisticsBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("cycleType", cycleType == null ? "" : cycleType);
        params.put("param", param);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.getLineStatistics, params, new ResponseObserver<StatisticsBean>() {
            @Override
            public void onSuccessful(StatisticsBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(StatisticsBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestChildLineStatistics(String agent_id, String cycleType, String param, DataCallBack<StatisticsBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("agent_id", agent_id);
        params.put("cycleType", cycleType == null ? "" : cycleType);
        params.put("param", param);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.getChildLineStatistics, params, new ResponseObserver<StatisticsBean>() {
            @Override
            public void onSuccessful(StatisticsBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(StatisticsBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestTradeMoneyCount(String cycleType, String param, DataCallBack<StatisticsTypeBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("cycleType", cycleType == null ? "" : cycleType);
        params.put("param", param);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.tradeMoneyCount, params, new ResponseObserver<StatisticsTypeBean>() {
            @Override
            public void onSuccessful(StatisticsTypeBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(StatisticsTypeBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

}
